//获取在min，max间随机数
function getRan(min, max) {
	return parseInt(Math.random() * (max - min + 1)) + min;
}


function RandomStr(num) {
	var result = "";
	for(var i = 0; i < num; i++) {
		var flag = getRan(1, 3)
		if(flag == 2) {
			result = result.concat(getRan(0, 9))

		} else if(flag == 1) {
			result = result.concat(String.fromCharCode(getRan(65, 90)))
		} else {
			result = result.concat(String.fromCharCode(getRan(97, 122)))
		}
	}
	return result;
}

//封装Cookie
function setCookie(key, value, date, path, domain, secure) {
	var str = "";
	if(key && value) {
		str += encodeURIComponent(key) + "=" + encodeURIComponent(value) + ";"
	}
	if(date instanceof Date) {
		str += "expires=" + date + ";"
	}
	if(path) {
		str += "path=" + path + ";"
	}
	if(domain) {
		str += "domain" + domain + ";"
	}
	if(secure == "secure") {
		str += "secure"
	}
	document.cookie = str;
}

function getAllCookie() {
	var obj = {};
	var str = document.cookie;
	if(str.indexOf(";") != -1) {
		var arr1 = str.split(";")
		for(i = 0; i < arr1.length; i++) {
			var arr2 = arr1[i].split("=");
			obj[decodeURIComponent(arr2[0].trim())] = decodeURIComponent(arr2[1].trim())
		}
	} else {
		if(str.indexOf("=") != -1) {
			var arr = str.split("=");
			obj[decodeURIComponent(arr[0].trim())] = decodeURIComponent(arr[1].trim())
		}
	}
	return obj;
}

function getValueById(key) {
	var obj = getAllCookie();
	return obj[key]

}

function removeCookie(key) {
	var date = new Date
	date.setDate(date.getDate() - 8)
	document.cookie = encodeURIComponent(key) + "= ;expires=" + date;
}